#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time       :   8:31
# Author     : Y4
# Site       : 
# File       : 012 协程.py
# Software   : PyCharm

'''
协程的底层就是通过生成器完成的
'''

import time

def task1():
    for i in range(3):
        print('A'+str(i))
        yield
        time.sleep(1)

def task2():
    for i in range(3):
        print('B'+str(i))
        yield
        time.sleep(1)

if __name__ == '__main__':
    g1 = task1()
    g2 = task2()

    while True:
        try:
            next(g1)
            next(g2)
        except:
            break